package ar.edu.uba.fi.jmit.monitorengine.backend.client.controller;

import java.util.LinkedList;

import ar.edu.uba.fi.jmit.monitorengine.backend.client.Monitorengine;
import ar.edu.uba.fi.jmit.monitorengine.backend.client.VisualizersService;
import ar.edu.uba.fi.jmit.monitorengine.backend.client.VisualizersServiceAsync;
import ar.edu.uba.fi.jmit.monitorengine.backend.client.view.VisualizersPanel;
import ar.edu.uba.fi.jmit.monitorengine.backend.shared.dto.VisualizerDTO;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class LoadedVisualizersController {
	
	private VisualizersServiceAsync visualizersService = GWT.create(VisualizersService.class);
	
	private Monitorengine mainModule;
	
	private VisualizersPanel panel;
	
	public LoadedVisualizersController(Monitorengine mainModule) {
		super();
		this.mainModule = mainModule;
		this.panel = mainModule.getVisualizersPanel();
		
	}

	public void showLoadedVisualizers() {
		GWT.log("Showing loaded visualizers ");
		visualizersService.getLoadedVisualizers(new AsyncCallback<LinkedList<VisualizerDTO>>() {
			
			@Override
			public void onSuccess(LinkedList<VisualizerDTO> visualizers) {
				GWT.log("Showing " + visualizers.size() + " visualizers");
				panel.showVisualizers(visualizers);
				mainModule.showVisualizersPanel();
			}
			
			@Override
			public void onFailure(Throwable arg0) {
				// TODO Auto-generated method stub
				//mostrar error
				GWT.log("Could not get visualizers", arg0);
			}
		});
	}

}
